<template>
    <div class="box">
        <div class="header">
            <van-nav-bar title="地址页" @click-left="$router.go(-1)">
                <template #left>
                    <van-icon name="arrow-left" size="25" color='black' />
                </template>
            </van-nav-bar>
        </div>
        <div class="main">
            <van-address-list v-model="chosenAddressId" :list="list" default-tag-text="默认" @add="onAdd"
                @edit="onEdit" />
        </div>
    </div>

</template>

<script>
import { addRessList, defaultAddress, addressUpdate } from "../../api/my";
import Vue from 'vue';
import { AddressList, Toast, NavBar } from 'vant';

Vue.use(AddressList);
Vue.use(Toast);
Vue.use(NavBar);
export default {
    data() {
        return {
            chosenAddressId: '1',
            list: [
                {
                    id: '1',
                    name: '张三',
                    tel: '13000000000',
                    address: '浙江省杭州市西湖区文三路 138 号东方通信大厦 7 楼 501 室',
                    isDefault: true,
                },
                {
                    id: '2',
                    name: '李四',
                    tel: '1310000000',
                    address: '浙江省杭州市拱墅区莫干山路 50 号',
                },
            ],
        };
    },
    methods: {
        onAdd() {
            Toast('新增地址');
            this.$router.push('/dizhi')

        },
        onEdit(item, index) {
            Toast('编辑地址:' + index);
        },


    },

    created() {
        // 地址列表
        addRessList({ userid: localStorage.getItem("userid") }).then(res => {
            console.log(res.data.data);
            // this.list = res.data.data
        })

        defaultAddress({ userid: localStorage.getItem("userid") }).then(res => {
            console.log(res);
        })

        addressUpdate({}).then(res => {
            console.log(res);
        })
    }
}
</script>

<style>
.header {
    text-align: center;
    line-height: 0.64rem;
    font-size: .18rem;
}
</style>